package com.Test;
import com.dao.MemberDao;
import com.dao.impl.MemberDaoImpl;
import com.entity.Member;
import com.util.DBUtil;
import org.junit.Test;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.Instant;
import java.util.Date;
import java.util.List;
public class TestMemberDaoImpl {
    private MemberDao memberDao=new MemberDaoImpl();
    @Test
    public void test1(){
        String sql = "delete from member where num=1";
        PreparedStatement preparedStatement=DBUtil.createPreparedStatement(sql);
        DBUtil.execUpdate(preparedStatement);
    }
    @Test
    public void testSelectall() {
        try {
            List<Member> list= memberDao.selectAll();
            list.forEach(System.out::println);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void testInsert(){
        Member member=new Member(null,"王五","男", Date.from(Instant.now()),"198",1,Date.from(Instant.now()));
        memberDao.insert(member);
    }
    @Test
    public void testSelectByNum(){
        Member member=memberDao.SelectByNum(2);
        System.out.println(member);
    }
    @Test
    public void testUpdate(){
        Member member=new Member(6,"王五","女", Date.from(Instant.now()),"198",1,Date.from(Instant.now()));
        memberDao.update(member);
    }
    @Test
    public void testSelectByName() {
            List<Member> list= memberDao.selectByName("王五").getList();
            list.forEach(System.out::println);
    }
}
